Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expire azure token as needed #615

Merged
merged 1 commit into from
Aug 12, 2024
Merged

expire azure token as needed #615

merged 1 commit into from
Aug 12, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Aug 12, 2024

  • The function createAzureToken in azuretoken.ts has been refactored to return an object of type AuthenticationToken. This marks a shift from the previous version where it just returned a string token, to the new version where it returns an object containing two properties, token (a string) and expiresOnTimestamp (a number). 🔄
  • An interface AuthenticationToken was introduced into azuretoken.ts. 🆕
  • Also, the _azureToken private property in nodehost.ts has been altered to hold an AuthenticationToken object as opposed to a single token string. 💾
  • The getLanguageModelConfiguration in nodehost.ts has been updated to refresh the _azureToken if it is not set, or if its expiresOnTimestamp is equal to or greater than the current time. This ensures that an expired token won't be used, improving reliability and security. ⏲️🔒
  • The packaging or concatenation process to make the token a Bearer token in getLanguageModelConfiguration now uses _azureToken.token as opposed to _azureToken. 👍

generated by pr-describe


export async function createAzureToken(
signal: AbortSignal
): Promise<AuthenticationToken> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter signal in the function createAzureToken is missing a type annotation. Please add a type annotation to improve code readability and maintainability. 📚

generated by pr-review-commit missing_param_type

if (
!this._azureToken ||
this._azureToken.expiresOnTimestamp >= Date.now()
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison this._azureToken.expiresOnTimestamp >= Date.now() seems to be incorrect. It should be this._azureToken.expiresOnTimestamp <= Date.now() to check if the token has expired. 🕰️

generated by pr-review-commit incorrect_comparison

if (
!this._azureToken ||
this._azureToken.expiresOnTimestamp >= Date.now()
)
this._azureToken = await createAzureToken(signal)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function createAzureToken is an async function but it's not being awaited here. This could lead to unexpected behavior. Please use await to ensure the promise is resolved before proceeding. 🔄

generated by pr-review-commit async_await

Copy link

There are some potential functional issues in the pull request:

  1. In azuretoken.ts the function createAzureToken now returns an object {token: azureToken.token, expiresOnTimestamp: azureToken.expiresOnTimestamp,}. In case azureToken.expiresOnTimestamp is not a number or not provided, this could cause issues in nodehost.ts where it's compared to Date.now().

  2. In nodehost.ts, the check for the token expiration this._azureToken.expiresOnTimestamp >= Date.now() should probably be this._azureToken.expiresOnTimestamp <= Date.now(). Right now, it's checking if the token's expiration timestamp is greater than or equal to the current timestamp, which means it will only update the token if it's not yet expired.

-                this._azureToken.expiresOnTimestamp >= Date.now()
+                this._azureToken.expiresOnTimestamp <= Date.now()
  1. Also, in nodehost.ts, there should be a null and type check for this._azureToken.expiresOnTimestamp before comparing it with Date.now().
-                !this._azureToken ||
-                this._azureToken.expiresOnTimestamp >= Date.now()
+                !this._azureToken ||
+                (typeof this._azureToken.expiresOnTimestamp === 'number' && this._azureToken.expiresOnTimestamp <= Date.now())

These changes should make the code safer and functionally correct.

generated by pr-review

@pelikhan pelikhan merged commit c61970a into main Aug 12, 2024
10 checks passed
@pelikhan pelikhan deleted the expireazuretoken branch August 12, 2024 16:51
@pelikhan
Copy link
Member Author

fix for #613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant